home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / test / testd.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  1.9 KB  |  68 lines  |  [TEXT/R*ch]

  1. (* This test works only for 32-bit implementations! *)
  2.  
  3. val maxint = 1073741823;
  4. val minint = ~maxint -1;
  5. infix seq
  6. fun e1 seq e2 = e2;
  7.  
  8. (~minint    seq "WRONG") handle Overflow => "OK";
  9. (abs minint seq "WRONG") handle Overflow => "OK";
  10. (maxint+1   seq "WRONG") handle Overflow => "OK";
  11. (minint-1   seq "WRONG") handle Overflow => "OK";
  12.  
  13. if maxint =  0x3fffffff then "OK" else "WRONG";
  14. if maxint =  0x3FFFFFFF then "OK" else "WRONG";
  15. if minint = ~0x40000000 then "OK" else "WRONG";
  16.  
  17. val sum = (op+) : int * int -> int;
  18. val diff = (op-) : int * int -> int;
  19. (sum (maxint,1)  seq "WRONG") handle Overflow => "OK";
  20. (diff (minint,1) seq "WRONG") handle Overflow => "OK";
  21.  
  22. (minint * ~1 seq  "WRONG") handle Overflow => "OK";
  23.  
  24. val prod = (op * ) : int * int -> int;
  25. (prod (minint,~1) seq "WRONG") handle Overflow => "OK";
  26.  
  27. fun checkDivMod i d =
  28.   let val q = i div d
  29.       val r = i mod d
  30.   in 
  31.       printVal i seq TextIO.output(TextIO.stdOut, " "); 
  32.       printVal d seq TextIO.output(TextIO.stdOut, "   ");
  33.       if (d * q + r = i) andalso
  34.       ((0 <= r andalso r < d) orelse (d < r andalso r <= 0))
  35.       then "OK" else "WRONG: problems with div, mod"
  36.   end;
  37.  
  38. checkDivMod 23 10;
  39. checkDivMod ~23 10;
  40. checkDivMod 23 ~10;
  41. checkDivMod ~23 ~10;
  42.  
  43. checkDivMod 100 10;
  44. checkDivMod ~100 10;
  45. checkDivMod 100 ~10;
  46. checkDivMod ~100 ~10;
  47.  
  48. checkDivMod 100 1;
  49. checkDivMod 100 ~1;
  50. checkDivMod 0 1;
  51. checkDivMod 0 ~1;
  52.  
  53. (100 div 0     seq  "WRONG") handle Div => "OK";
  54. (100 mod 0     seq  "WRONG") handle Div => "OK";
  55. (minint div ~1 seq  "WRONG") handle Overflow => "OK";
  56.  
  57. val maxri = real maxint;
  58. val minri = real minint;
  59.  
  60. if floor 3.0 = 3 then "OK" else "WRONG";
  61. if floor 3.14 = 3 then "OK" else "WRONG";
  62. if floor ~3.0 = ~3 then "OK" else "WRONG";
  63. if floor ~3.14 = ~4 then "OK" else "WRONG";
  64. if floor(maxri + 0.9) = maxint then "OK" else "WRONG";
  65. if floor minri = minint then "OK" else "WRONG";
  66. (floor (minri - 0.1) seq  "WRONG") handle Overflow => "OK";
  67. (floor (maxri + 1.0) seq  "WRONG") handle Overflow => "OK";
  68.